package sm.codec;

import org.apache.mina.core.buffer.IoBuffer;

import sm.codec.api.Codec;
import sm.codec.exception.DecodeException;
import sm.codec.exception.EncodeException;
import sm.codec.type.NullValue;
import sm.def.Type;

public class RecordCodec extends AbstractStructCodec implements Codec {
	@Override
	public Object decode(IoBuffer buffer) throws DecodeException {
		return decode(buffer, Type.RECORD_TYPE);
	}

	@Override
	public void encode(IoBuffer buffer, Object obj) throws EncodeException {
		if (obj == null || obj instanceof NullValue) {
			buffer.put((byte) 0x6F);
		} else {
			super.encode(buffer, obj, Type.RECORD_TYPE);
		}
	}
}
